package ast;
/**
 * <code>SimpleVisitor</code>
 * Simple implementation of a Visitor

 * It traverses the tree printing on stdout what it finds in the nodes of the AST
 * The input program is therefore reproduced on stdout without indentation
 *
 */
public class SimpleVisitor implements Visitor {


    public Object visit (List n) {
	n.left.accept(this);
	if (n.right!=null) n.right.accept(this);
	return null;
    }

    public Object visit (DeclNode n) {
	System.out.println(n.type + " " + n.name + ";");
	return null;
    }

    public Object visit (StmtNode n) {
	return null;
    }

    public Object visit (AddNode n) {
	n.left.accept(this);
	System.out.print("+");
	n.right.accept(this);
	return null;
    }

     public Object visit (TimesNode n) {
	n.left.accept(this);
	System.out.print("*");
	n.right.accept(this);
	return null;
    }

    public Object visit (IntNumNode n) {
	System.out.print(n.value);
	return null;
    }

    public Object visit (Node n) {
	n.left.accept(this);
	n.right.accept(this);
	return null;
    }

    public Object visit (ExprNode n) {
	n.left.accept(this);
	n.right.accept(this);
	return null;
    }

    public Object visit (AndNode n) {
	n.left.accept(this);
	System.out.print("&&");
	n.right.accept(this);
	return null;
    }

    public Object visit (DivideNode n) {
	n.left.accept(this);
	System.out.print("/");
	n.right.accept(this);
	return null;
    }

    public Object visit (EqualNode n) {
	n.left.accept(this);
	System.out.print("==");
	n.right.accept(this);
	return null;
    }

    public Object visit (GreaterEqualNode n) {
	n.left.accept(this);
	System.out.print(">=");
	n.right.accept(this);
	return null;
    }

    public Object visit (GreaterNode n) {
	n.left.accept(this);
	System.out.print(">");
	n.right.accept(this);
	return null;
    }

    public Object visit (InNode n) {
	n.left.accept(this);
	System.out.print("+");
	n.right.accept(this);
	return null;
    }

    public Object visit (LessEqualNode n) {
	n.left.accept(this);
	System.out.print("<=");
	n.right.accept(this);
	return null;
    }

    public Object visit (LessNode n) {
	n.left.accept(this);
	System.out.print("<");
	n.right.accept(this);
	return null;
    }

    public Object visit (MinusNode n) {
	n.left.accept(this);
	System.out.print("-");
	n.right.accept(this);
	return null;
    }

    public Object visit (NotEqualNode n) {
	n.left.accept(this);
	System.out.print("!=");
	n.right.accept(this);
	return null;
    }

    public Object visit (NotInNode n) {
	n.left.accept(this);
	System.out.print("notin");
	n.right.accept(this);
	return null;
    }

    public Object visit (OrNode n) {
	n.left.accept(this);
	System.out.print("||");
	n.right.accept(this);
	return null;
    }

    public Object visit (PowerNode n) {
	n.left.accept(this);
	System.out.print("^");
	n.right.accept(this);
	return null;
    }

    public Object visit (RealNumNode n) {
	System.out.print(n.value.floatValue());
	return null;
    }

    public Object visit (StringNode n) {
	System.out.print(n.value.toString());
	return null;
    }

    public Object visit (FalseNode n) {
        System.out.print(n.value.toString());
        return null;
    }

    public Object visit (TrueNode n) {
        System.out.print(n.value.toString());
        return null;
    }

    public Object visit (NotNode n) {
        n.left.accept(this);
        System.out.print("!");
        return null;
    }

    public Object visit(LengthNode n) {
        n.left.accept(this);
        System.out.print("length");
        return null;
    }

    public Object visit(MethodNode n) {
        System.out.print(n.value.toString());
        return null;
    }

    public Object visit(VarNode n) {
        System.out.print(n.value.toString());
        return null;
    }
   
}